#ifndef __SMEMORY_H
#define __SMEMORY_H

#ifdef	_DEBUG
#define DEBUG_MEMORY_ALLOCATOR
#endif

union memory_obj{
	memory_obj* next;
	char	data[1];
};

class small_memory_allocator
{
public:
};

struct memory_cookie;

struct memory_debug
{
#ifdef DEBUG_MEMORY_ALLOCATOR
	int _id;
	long _lock;
	int _break_id;
	memory_cookie *_list;
#endif
};

class memory : public memory_debug
{
	memory();
	~memory();
	static memory *_instance;
	static void create_instance();
	void debug_malloc(memory_cookie *);
	void debug_free(memory_cookie *);
	
public:
	void* malloc(size_t size);
	void  free(void *p);
	void set_break(int i);
	static memory &instance();
};

#ifndef DEBUG_MEMORY_ALLOCATOR
void memory::debug_malloc(memory_cookie *){}
void memory::debug_free(memory_cookie *){}
inline void memory::set_break(int i){}
#endif


template<int debug>
struct memory_debug_cookie
{
	memory_cookie *last;
	memory_cookie *next;
};

template<> struct memory_debug_cookie<0>{};

struct memory_cookie 
	: public memory_debug_cookie< (sizeof(memory) > sizeof(memory_debug_cookie<0>)) >
{
	int size;
};




#endif